home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_07 / plauger / istread < prev    next >
Encoding:
Text File  |  1994-05-03  |  456 b   |  26 lines

  1. // istread -- istream::read(char *, int)
  2.  
  3. #include <istream>
  4.  
  5. istream& istream::read(char *s, int n)
  6.     {    // get at most n bytes
  7.     _Chcount = 0;
  8.     _TRY_IO_BEGIN
  9.     if (ipfx(1))
  10.         {    // extract arbitrary characters
  11.         int ch;
  12.         for (; 0 < n; --n)
  13.             if ((ch = rdbuf()->sbumpc()) == EOF)
  14.                 {    // record eof and quit
  15.                 setstate(failbit);
  16.                 break;
  17.                 }
  18.             else
  19.                 *s++ = ch, ++_Chcount;
  20.         }
  21.     isfx();
  22.     _CATCH_IO_END
  23.     return (*this);
  24.     }
  25.  
  26.